﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.Core;
using ZhouYu.DreamTour.Core.LogFourNet;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;

namespace ZhouYu.DreamTour.DAL.Repository
{
    public class ScenicRepository: IScenicRepository
    {
        #region 获取单一主图片集合
        /// <summary>
        /// 获取单一主图片集合
        /// </summary>
        /// <returns></returns>
        public List<ScenicExhibition> GetScenicPicList()
        {
            //sql语句
            string sql = @"SELECT s.`Id` ScenicSpot_Id,ParentId,sc.Pic_Url Pic_Url,sc.`Pic_Id` Pic_Id 
                            FROM ScenicSpot s INNER JOIN ScenicPic sc ON sc.`Scenic_Id`=s.`Id` WHERE sc.`Pic_Id` BETWEEN 1 AND 7";
            DynamicParameters dynamicParameters = null;
            //调用查询集合方法
            return DapperHelper<ScenicExhibition>.QueryList(sql, dynamicParameters);
        }
        #endregion

        #region 根据主图查询次图
        /// <summary>
        /// 根据主图查询次图
        /// </summary>
        /// <returns></returns>
        public List<Scenicpic> GetPicListById(int Pic_Id)
        {
            //sql语句
            string sql = @"SELECT Pic_Id,Pic_Url FROM ScenicPic WHERE ParentId =@Pic_Id";
            DynamicParameters dynamicParameters = new DynamicParameters();
            dynamicParameters.Add("@Pic_Id", Pic_Id);
            //调用查询集合方法
            return DapperHelper<Scenicpic>.QueryList(sql, dynamicParameters);
        }
        #endregion

        #region 根据ID查询具体旅游景点详情
        /// <summary>
        /// 根据ID查询具体旅游景点详情
        /// </summary>
        /// <returns></returns>
        public ScenicExhibition GetScenicDetails(int TouristRouteId)
        {
            //sql语句
            string sql = @"SELECT DISTINCT t.Id Id,t.TName TName,sc.Pic_Url,t.RouteIntroduce RouteIntroduce,ProductNumber,OutPlace,OverPlace,
                        t.Price Price,t.Price DiscountPrice,OutDate,Duration,s.Context Context
                        FROM TouristRoute AS t
                        INNER JOIN ScenicSpot AS s ON t.ScenicSpotId=s.Id
                        INNER JOIN ScenicPic AS sc ON sc.Scenic_Id=s.Id
                        WHERE t.`Id`=@TouristRouteId AND sc.ParentId=0";
            DynamicParameters dynamicParameters = new DynamicParameters();
            dynamicParameters.Add("@TouristRouteId", TouristRouteId);
            //调用查询集合方法
            return DapperHelper<ScenicExhibition>.QuerySingleOrDefault(sql, dynamicParameters);
        }
        #endregion

        #region 查询旅游路线集合
        /// <summary>
        /// 查询旅游路线集合
        /// </summary>
        /// <returns></returns>
        public List<ScenicExhibition> GetScenicExhibitions()
        {
            //sql语句
            string sql = @"SELECT DISTINCT t.Id Id,s.`BeCarefulInfoId`,t.TName TName,t.RouteIntroduce RouteIntroduce,ProductNumber,OutPlace,OverPlace,
                        t.Price Price,t.Price DiscountPrice,OutDate,Duration,s.Context Context,t.HotelId,s.Certification
                        FROM TouristRoute AS t
                        LEFT JOIN ScenicSpot AS s ON t.ScenicSpotId=s.Id
                        LEFT JOIN ScenicPic AS sc ON sc.Scenic_Id=s.Id LIMIT 0,7";
            DynamicParameters dynamicParameters = null;
            //调用查询集合方法
            return Multiply(DapperHelper<ScenicExhibition>.QueryList(sql, dynamicParameters));
        }
        #endregion

        #region 没有进行折扣的价格
        /// <summary>
        /// 没有进行折扣的价格
        /// </summary>
        public List<ScenicExhibition> Multiply(List<ScenicExhibition> scenicExhibitions)
        {
            //循环
            foreach (var item in scenicExhibitions)
            {
                item.DiscountPrice = item.Price * 2;
            }
            return scenicExhibitions;
        }
        #endregion

        #region 时间格式转换的方法
        /// <summary>
        /// 时间格式转换的方法
        /// </summary>
        public ScenicExhibition DateTimeShow(ScenicExhibition scenicExhibitions)
        {
            //提取年月方法
            DateTime dt = DateTime.Parse(scenicExhibitions.OutDate);
            string str = dt.ToString("yyyy-MM-dd");
            scenicExhibitions.OutDate = str;
            return scenicExhibitions;
        }
        #endregion

        #region 查询景点的注意事项
        /// <summary>
        /// 查询景点的注意事项
        /// </summary>
        /// <returns></returns>
        public List<BeCarefulInfo> GetBeCarefulInfo(int BeCarefulInfoId)
        {
            string sql = @"SELECT Id,BeInfo FROM BeCarefulInfo b WHERE BeCarefulInfoId=@BeCarefulInfoId";
            DynamicParameters dynamicParameters = new DynamicParameters();
            dynamicParameters.Add("@BeCarefulInfoId", BeCarefulInfoId);
            return DapperHelper<BeCarefulInfo>.QueryList(sql, dynamicParameters);
        }
        #endregion
    }
}
